package com.factory;

import com.zbkj.crmeb.finance.service.process.IRechargeOrderProcess;
import com.zbkj.crmeb.order.oprocess.IOrderProcess;
import com.zbkj.crmeb.order.pprocess.IOrangePayOrderProcess;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;


@Service("commonFactory")
public class CommonFactory implements BeanFactoryAware, InitializingBean {

    private static final Logger logger = LoggerFactory.getLogger(CommonFactory.class);
    private BeanFactory beanFactory;

    /**订单类型  (1觅兰订单, 2: 橙子订单) */
    private Map<Integer,String> orderTypeMap = new HashMap<Integer, String>();
    /**支付类型*/
    private Map<String,String> payTypeMap = new HashMap<String, String>();

	/**充值类型（1觅兰微信充值 2觅兰橙子充值）*/
	private Map<Integer,String> rechargeTypeMap = new HashMap<Integer, String>();


    	public IOrderProcess getOrderType(Integer type) {
			 if (type==null) {
		            return null;
		        }
	        if (orderTypeMap == null) {
	        	logger.error("orderTypeMap为空,初始化失败");
	            return null;
	        }
	        String serviceName = orderTypeMap.get(type);
	        return (IOrderProcess) beanFactory.getBean(serviceName);
		}

		public IOrangePayOrderProcess getPayType(String type) {
			 if (type==null) {
		            return null;
		        }
	        if (payTypeMap == null) {
	        	logger.error("payTypeMap为空,初始化失败");
	            return null;
	        }
	        String serviceName = payTypeMap.get(type);
	        return (IOrangePayOrderProcess) beanFactory.getBean(serviceName);
		}

		public IRechargeOrderProcess getRechargeType(Integer type) {
			if (type==null) {
				return null;
			}
			if (rechargeTypeMap == null) {
				logger.error("rechargeTypeMap,初始化失败");
				return null;
			}
			String serviceName = rechargeTypeMap.get(type);
			return (IRechargeOrderProcess) beanFactory.getBean(serviceName);
		}
		
	@Override
    public void setBeanFactory(BeanFactory beanFactory) {
		this.beanFactory = beanFactory;
	}


	@Override
	public void afterPropertiesSet() throws Exception {

		// 订单类型(1觅兰订单, 2: 橙子订单 3: 香港支付 4: 汇付聚合)
		orderTypeMap.put(1, "stroreOrderProcess");
		orderTypeMap.put(2, "orangeOrderProcess");
		orderTypeMap.put(3, "hkpayOrderProcess");
		orderTypeMap.put(4, "adapayDegreeOrderProcess");
		orderTypeMap.put(5, "adapayCnOrderProcess");
		orderTypeMap.put(6, "lianlianDegreeOrderProcess");
		
		// 支付类型
		payTypeMap.put("yue", "yueOrderProcess");
		payTypeMap.put("weixin", "wechatOrderProcess");
		payTypeMap.put("orage", "wechatOrderProcess");
		payTypeMap.put("tmall", "tmallOrderProcess");
		payTypeMap.put("hkpay", "wechat4hkOrderProcess");
		payTypeMap.put("adapay_degree", "adapayDegreePayOrderProcess");
		payTypeMap.put("adapay_cn", "adapayCnPayOrderProcess");
		payTypeMap.put("other", "yueOrderProcess");
		payTypeMap.put("offline", "offlineOrderProcess");
		payTypeMap.put("lianlian_degree", "lianlianDegreePayOrderProcess");

		// 充值类型
		rechargeTypeMap.put(1,"storeRechargeProcess");
		rechargeTypeMap.put(2,"orangeRechargeProcess");
		rechargeTypeMap.put(3,"hkpayRechargeProcess");
		rechargeTypeMap.put(4,"adapayDegreePayOrderProcess");
		rechargeTypeMap.put(5,"adapayCnPayOrderProcess");
		rechargeTypeMap.put(6,"lianlianDegreePayOrderProcess");
	}
	
}
